﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.JinShengService;
using CommunitySystem.PageView;

namespace CommunitySystem
{
    public partial class SelectJSSHDetailWindow : ChildWindow
    {
        private JinShengServiceClient _client = new JinShengServiceClient();

        private JinShenMHelp _JsM=null;
        private JinShen_MainInfoLSJL jsls = null;
        public SelectJSSHDetailWindow(JinShenMHelp jsM)
        {
            InitializeComponent();
            _JsM = jsM;
            _client.GetJinShen_SHJLDetailAsync(string.Format(" and JSMID={0} order by m.BLDate ", jsM.ID));
            _client.GetJinShen_SHJLDetailCompleted += (ss, ee) => {
                this.dg.ItemsSource = ee.Result;
            
            };

            _client.GetJinShen_MainInfoLSJLCompleted += (ss, ee) => {

                jsls = ee.Result;
                Chakan();
            };
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private JinShen_SHJLDetail attach = null;
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton hbtn = sender as HyperlinkButton;

            attach = hbtn.Tag as JinShen_SHJLDetail;

            _client.GetJinShen_MainInfoLSJLAsync(attach.JSID.ToString(), attach.Name);

           // Chakan();
                
        }

        private void Chakan()
        {
            if (attach.Name == "方案审核" || attach.Name == "人员审核")
            {
                SelJSWindow win = new SelJSWindow(jsls, attach.Name);
                win.Show();
            }
         

            if (attach.Name == "竞争上岗及民主测评情况")
            {

                CandidatorCheckWindow window = new CandidatorCheckWindow(jsls.JinShen_MainInfoInfo.First(), "", true);
                window.Show();

            }
            if (attach.Name == "人员核定情况")
            {
                ChooseCandidatorWindow window = new ChooseCandidatorWindow(jsls.JinShen_MainInfoInfo.First(), true);
                window.Show();

            }
        }

        private void dg_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            HyperlinkButton hb = dg.Columns[5].GetCellContent(e.Row).FindName("hbtn") as HyperlinkButton;
            var jshelp = e.Row.DataContext as JinShen_SHJLDetail;
            if(!string.IsNullOrEmpty(jshelp.Status))
                hb.Content="查看";
        }

      
    }
}

